import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';


const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};

@Injectable({
  providedIn: 'root'
})
export class AuthService {

  constructor(private http: HttpClient) { }


  getHello() {
    return this.http.get('/api/hello');
  }

  postLoginBasicAuth(username: string, password: string) {
    // application/x-www-form-urlencoded
    let body = new FormData();
    body.set('username', username);
    body.set('password', password);

    return this.http.post('/api/login', body)
  }

  getMe(){
    var token = localStorage.getItem('token')
    var tokenString: string = ""
    if (token != null) {
      tokenString = token
    }
    
    // var headers = {"x-access-token": token}
    const headers = { 'x-access-token': tokenString}
    
    return this.http.get('/api/me', {headers})
  }

}
